<?php

namespace App\Model;

use Validator;

trait ValidatorModel
{
    public function validator(array $data , array $rules)
    {
        $validator = Validator::make($data, $rules);
        if (!$validator->passes()) {

            $msg = array_reduce($validator->errors()->all(),function ($v1 , $v2){
                return $v1 ."\n". $v2;
            },'');

            return $msg;
        }
    }


    public function getRules($data)
    {
        return array_filter (static::$rules,function ($key) use ($data){
            return in_array($key , array_keys($data));
        }, ARRAY_FILTER_USE_KEY);

    }
}